﻿Imports System.Drawing.Drawing2D
Public Class ContourEditor

    Public SettingPannel As Pannel '当前绘图类
    Private filename As String '背景图文件名
    Private arrBrushStyleName() As String '画刷样式的名称数组，0-4
    Private brhStyle() As HatchBrush  '画刷数组
    Private arrSymbolShapeName() As String '标志形状的名称数组，0-4
    Private BoolRefresh As Boolean = False '刷新标志

    Property Contours() As Contours
        Get
            Return Me.ContourPaintForm1.ContourPaintSetting.ContourPannel.Contours
        End Get
        Set(ByVal value As Contours)
            Me.ContourPaintForm1.ContourPaintSetting.ContourPannel.Contours = value
        End Set
    End Property

    Private Sub ContourPorpertyForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.SettingPannel = Me.ContourPaintForm1.ContourPaintSetting.ContourPannel

        '初始化网格不可见
        Me.ContourPaintForm1.ContourPaintSetting.ContourPannel.Axes.LeftAxis.AxisGridding.AxisGriddingVisible = False
        Me.ContourPaintForm1.ContourPaintSetting.ContourPannel.Axes.BottomAxis.AxisGridding.AxisGriddingVisible = False
        '初始化坐标不可见
        Me.ContourPaintForm1.ContourPaintSetting.ContourPannel.Axes.LeftAxis.AxisLine.AxisVisible = False
        Me.ContourPaintForm1.ContourPaintSetting.ContourPannel.Axes.BottomAxis.AxisLine.AxisVisible = False
        Me.ContourPaintForm1.ContourPaintSetting.ContourPannel.Axes.RightAxis.AxisLine.AxisVisible = False
        Me.ContourPaintForm1.ContourPaintSetting.ContourPannel.Axes.TopAxis.AxisLine.AxisVisible = False
        '坐标标注
        Me.ContourPaintForm1.ContourPaintSetting.ContourPannel.Axes.LeftAxis.AxisLabel.LabelVisible = False
        Me.ContourPaintForm1.ContourPaintSetting.ContourPannel.Axes.BottomAxis.AxisLabel.LabelVisible = False

        '坐标标注
        Me.ContourPaintForm1.ContourPaintSetting.ContourPannel.Axes.LeftAxis.AxisTitle.TitleVisible = False
        Me.ContourPaintForm1.ContourPaintSetting.ContourPannel.Axes.BottomAxis.AxisTitle.TitleVisible = False

        '坐标刻度
        Me.ContourPaintForm1.ContourPaintSetting.ContourPannel.Axes.LeftAxis.MainAxisScale.ScaleVisible = False
        Me.ContourPaintForm1.ContourPaintSetting.ContourPannel.Axes.BottomAxis.MainAxisScale.ScaleVisible = False

        '初始化坐标的位置
        ActivePaintForm.ContourPaintSetting.ContourPannel.Axes.BottomAxis.MainAxisScale.Min = ActivePaintForm.ContourPaintSetting.ContourPannel.Contours.Xmin
        ActivePaintForm.ContourPaintSetting.ContourPannel.Axes.BottomAxis.MainAxisScale.Max = ActivePaintForm.ContourPaintSetting.ContourPannel.Contours.Xmax
        ActivePaintForm.ContourPaintSetting.ContourPannel.Axes.BottomAxis.MainAxisScale.Increase = (ActivePaintForm.ContourPaintSetting.ContourPannel.Contours.Xmax - ActivePaintForm.ContourPaintSetting.ContourPannel.Contours.Xmin) / (ActivePaintForm.ContourPaintSetting.ContourPannel.Contours.nCol - 1)
        ActivePaintForm.ContourPaintSetting.ContourPannel.Axes.LeftAxis.MainAxisScale.Min = ActivePaintForm.ContourPaintSetting.ContourPannel.Contours.Ymin
        ActivePaintForm.ContourPaintSetting.ContourPannel.Axes.LeftAxis.MainAxisScale.Max = ActivePaintForm.ContourPaintSetting.ContourPannel.Contours.Ymax
        ActivePaintForm.ContourPaintSetting.ContourPannel.Axes.LeftAxis.MainAxisScale.Increase = (ActivePaintForm.ContourPaintSetting.ContourPannel.Contours.Ymax - ActivePaintForm.ContourPaintSetting.ContourPannel.Contours.Ymin) / (ActivePaintForm.ContourPaintSetting.ContourPannel.Contours.nRow - 1)

        '等值线光滑
        Me.chkSlip.Checked = Me.SettingPannel.Contours.Slip
        '初始化对话框的设置
        BoolRefresh = False
        InitialBrushStyle() '初始化等值线填充画刷
        If Not SettingPannel Is Nothing Then
            Dim i As Double
            ListBoxContour.Items.Clear()
            For i = 0 To Me.ContourPaintForm1.ContourPaintSetting.ContourPannel.Contours.ContourValueSetting.ContourValue.Length - 1
                ListBoxContour.Items.Add(CSng(ActivePaintForm.ContourPaintSetting.ContourPannel.Contours.ContourValueSetting.ContourValue(i))) '加入等值线值
            Next
            If ListBoxContour.Items.Count > 0 Then '如果不零则设置第一项为选中
                ListBoxContour.SelectedIndex = 0
            End If
        End If
        BoolRefresh = True
        If Not SettingPannel Is Nothing Then
            Dim i As Double
            For i = 0 To ListBoxContour.Items.Count - 1
                txtNumber.Value = SettingPannel.Contours.ArrayContour(i).ContourLine.Number
            Next
        End If

    End Sub
    Private Sub cmdApplication_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdApplication.Click
        Me.ReflashAll()
    End Sub
    Private Sub ReflashAll()
        '如果当前窗体为等值线绘图窗体，则根据用户的选择改变
        If BoolRefresh = True Then '
            ActivePaintForm.Refresh()
        End If
    End Sub

    Private Sub cmdInsert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        InsertBackImage(SettingPannel)
        filename = ImageFileName
        Me.Refresh()
        Me.ReflashAll()
    End Sub
    Private Sub picBack_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs)
        Dim rect As Rectangle
        'rect.Width = picBack.Width
        'rect.Height = picBack.Height
        If filename <> "" Then
            Dim img As Image = Image.FromFile(filename)
            If TypeOf (img) Is Image Then
                e.Graphics.DrawImage(img, rect)
            End If
        End If

    End Sub


    Private Sub cmdIntialContour_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim newInitial As New dlgInitialContour
    End Sub


    Private Sub chkContourVisible_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkContourVisible.CheckedChanged
        If Not SettingPannel Is Nothing Then
            Dim i As Double
            For i = 0 To ListBoxContour.SelectedItems.Count - 1
                SettingPannel.Contours.ArrayContour(ListBoxContour.SelectedIndices(i)).ContourLine.ContourLineVisible = chkContourVisible.Checked
            Next
        End If
        Me.ReflashAll()
    End Sub

    Private Sub ListBoxContour_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBoxContour.SelectedIndexChanged
        BoolRefresh = False
        If Not SettingPannel Is Nothing Then
            '根据当前选中的等值线值确定设置对话框中的等值线选项
            chkContourVisible.Checked = SettingPannel.Contours.ArrayContour(ListBoxContour.SelectedIndex).ContourLine.ContourLineVisible '等值线
            chkContourLabelVisible.Checked = SettingPannel.Contours.ArrayContour(ListBoxContour.SelectedIndex).ContourLine.LabelVisible
            chkContourFillVisible.Checked = SettingPannel.Contours.ArrayContour(ListBoxContour.SelectedIndex).ContourFill.ContourFillVisible
            ForeTransparent.Value = SettingPannel.Contours.ArrayContour(ListBoxContour.SelectedIndex).ContourFill.ForeTransparent
            BackTransparent.Value = SettingPannel.Contours.ArrayContour(ListBoxContour.SelectedIndex).ContourFill.BackTransparent
            cmbContourFillMode.SelectedIndex = SettingPannel.Contours.ArrayContour(ListBoxContour.SelectedIndex).ContourFill.BrushStyle '画刷样式
            cmbBrushStyle.SelectedIndex = SettingPannel.Contours.ArrayContour(ListBoxContour.SelectedIndex).ContourFill.HatchStyle '图案画刷的样式

        End If
        Me.Refresh()
        BoolRefresh = True
    End Sub

    Private Sub cmdContourLineStyle_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdContourLineStyle.Click
        If Not SettingPannel Is Nothing Then
            '分别赋给属性值，进行值传递，并调整宽度比例
            Dim frmLineStyle As New LineStyleEditor
            frmLineStyle.penCurLineStyle.DashStyle = SettingPannel.Contours.ArrayContour(ListBoxContour.SelectedIndex).ContourLine.PenProperty.DashStyle
            frmLineStyle.penCurLineStyle.Width = SettingPannel.Contours.ArrayContour(ListBoxContour.SelectedIndex).ContourLine.PenProperty.WidthReal
            frmLineStyle.penCurLineStyle.Color = Color.FromArgb(SettingPannel.Contours.ArrayContour(ListBoxContour.SelectedIndex).ContourLine.PenProperty.color)
            If frmLineStyle.ShowDialog() = Windows.Forms.DialogResult.OK Then '如果用户点击确定，则将线形编程器的画笔给当前画笔
                Dim i As Double
                For i = 0 To ListBoxContour.SelectedItems.Count - 1
                    SettingPannel.Contours.ArrayContour(ListBoxContour.SelectedIndices(i)).ContourLine.PenProperty.DashStyle = frmLineStyle.penCurLineStyle.DashStyle
                    SettingPannel.Contours.ArrayContour(ListBoxContour.SelectedIndices(i)).ContourLine.PenProperty.WidthReal = frmLineStyle.penCurLineStyle.Width
                    SettingPannel.Contours.ArrayContour(ListBoxContour.SelectedIndices(i)).ContourLine.PenProperty.color = frmLineStyle.penCurLineStyle.Color.ToArgb
                Next
                Me.ReflashAll()
                Me.Refresh()
            End If
        End If
        '根据当前选中的边轴确定是否绘图该座标线
    End Sub

    Private Sub picContourLineStyle_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picContourLineStyle.Click

    End Sub

    Private Sub picContourLineStyle_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles picContourLineStyle.Paint
        '绘制坐标线的线型
        If Not SettingPannel Is Nothing Then
            '根据当前选中的边轴确定是否绘图该座标线
            'Dim myMatrix As New Matrix()
            'myMatrix.Scale(1 / PannelSetting.gScale, 1 / PannelSetting.gScale) '调整比例
            'e.Graphics.Transform = myMatrix
            If ListBoxContour.Items.Count > 0 Then
                If ListBoxContour.SelectedIndex < 0 Then
                    ListBoxContour.SelectedIndex = 0
                End If
                Dim ContourLinePen As New Pen(Color.FromArgb(SettingPannel.Contours.ArrayContour(ListBoxContour.SelectedIndex).ContourLine.PenProperty.color))
                ContourLinePen.Width = SettingPannel.Contours.ArrayContour(ListBoxContour.SelectedIndex).ContourLine.PenProperty.WidthReal
                ContourLinePen.DashStyle = SettingPannel.Contours.ArrayContour(ListBoxContour.SelectedIndex).ContourLine.PenProperty.DashStyle
                e.Graphics.DrawLine(ContourLinePen, 0, CInt(e.ClipRectangle.Height / 2), CInt(e.ClipRectangle.Width), CInt(e.ClipRectangle.Height / 2))
            End If
        End If
    End Sub

    Private Sub chkContourLabelVisible_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkContourLabelVisible.CheckedChanged
        If Not SettingPannel Is Nothing Then
            '根据当前选中的边轴确定是否绘该座标线
            Dim i As Double
            For i = 0 To ListBoxContour.SelectedItems.Count - 1
                SettingPannel.Contours.ArrayContour(ListBoxContour.SelectedIndices(i)).ContourLine.LabelVisible = chkContourLabelVisible.Checked
            Next
        End If
        Me.ReflashAll()
    End Sub

    Private Sub cmdContourLabelFont_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdContourLabelFont.Click
        Dim fontDlg As New FontDialog
        If Not SettingPannel Is Nothing Then
            fontDlg.Font = SettingPannel.Contours.ArrayContour(ListBoxContour.SelectedIndex).ContourLine.LabelFont
            If fontDlg.ShowDialog() = Windows.Forms.DialogResult.OK Then '如果用户点击确定，则将线形编程器的画笔给当前画笔
                Dim i As Double
                For i = 0 To ListBoxContour.SelectedItems.Count - 1
                    SettingPannel.Contours.ArrayContour(ListBoxContour.SelectedIndices(i)).ContourLine.LabelFont = fontDlg.Font
                Next
                Me.ReflashAll()
                Me.Refresh()
            End If
        End If
    End Sub
    Private Sub picContourLabelFont_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles picContourLabelFont.Paint
        If ListBoxContour.SelectedIndex >= 0 Then
            Dim mycolor As Color = Color.Black
            Dim myfont As Font = New Font(SettingPannel.Contours.ArrayContour(ListBoxContour.SelectedIndex).ContourLine.LabelFont, FontStyle.Regular)
            If Not SettingPannel Is Nothing Then
                mycolor = SettingPannel.Contours.ArrayContour(ListBoxContour.SelectedIndex).ContourLine.LabelColor
                myfont = SettingPannel.Contours.ArrayContour(ListBoxContour.SelectedIndex).ContourLine.LabelFont
            End If
            Dim mybrush As New SolidBrush(mycolor)
            e.Graphics.DrawString("示例", myfont, mybrush, 5, 5)
        End If
    End Sub

    '填充样式--------------------------------------------------------------------------------
    Public Sub InitialBrushStyle()
        '初始化绘图画刷等
        cmbContourFillMode.SelectedIndex = 0 '实体填充
        cmbBrushStyle.DrawMode = Windows.Forms.DrawMode.OwnerDrawFixed '设置为可重绘下拉列表框
        cmbBrushStyle.DropDownStyle = ComboBoxStyle.DropDownList '设置为下拉列表框
        Dim i As Integer
        ReDim arrBrushStyleName(0 To 50)
        For i = 0 To 50
            Dim myhatchstyle As HatchStyle
            myhatchstyle = i
            arrBrushStyleName(i) = myhatchstyle.ToString
        Next
        ReDim brhStyle(0 To 50)
        For i = 0 To 50
            Dim myhatchstyle As HatchStyle
            myhatchstyle = i
            brhStyle(i) = New HatchBrush(myhatchstyle, Color.Red, Color.Yellow)
        Next
        cmbBrushStyle.DataSource = arrBrushStyleName '这条语句不能放到前面

        '初始化为实体填充时变灰
        cmbBrushStyle.Enabled = False
        cmdBackColor.Enabled = False
        BackTransparent.Enabled = False
    End Sub
    Public Sub DrawItemBrushStyle(ByVal e As System.Windows.Forms.DrawItemEventArgs) '绘制填充样式
        e.Graphics.FillRectangle(Brushes.RoyalBlue, e.Bounds)
        e.Graphics.FillRectangle(brhStyle(e.Index), 3, e.Bounds.Y + 3, e.Bounds.Height - 6, e.Bounds.Height - 6)
        e.Graphics.DrawString(arrBrushStyleName(e.Index), e.Font, Brushes.White, 3 + 3 + e.Bounds.Height - 6, e.Bounds.Y + 3)
        'is the mouse hovering over a combobox item??			
        If (e.State = DrawItemState.None) Then
            'this code keeps the last item drawn from having a Bisque background. 
            e.Graphics.FillRectangle(Brushes.White, e.Bounds)
            e.Graphics.FillRectangle(brhStyle(e.Index), 3, e.Bounds.Y + 3, e.Bounds.Height - 6, e.Bounds.Height - 6)
            e.Graphics.DrawString(arrBrushStyleName(e.Index), e.Font, Brushes.Black, 3 + 3 + e.Bounds.Height - 6, e.Bounds.Y + 3)
        End If
    End Sub

    Private Sub cmbBrushStyle_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles cmbBrushStyle.DrawItem
        DrawItemBrushStyle(e)
    End Sub

    Private Sub cmbBrushStyle_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbBrushStyle.SelectedIndexChanged
        If Not SettingPannel Is Nothing Then
            '根据当前选中的边轴确定是否绘该座标线
            Dim i As Double
            For i = 0 To ListBoxContour.SelectedItems.Count - 1
                SettingPannel.Contours.ArrayContour(ListBoxContour.SelectedIndices(i)).ContourFill.HatchStyle = cmbBrushStyle.SelectedIndex '图案画刷的样式
            Next
        End If

        Me.ReflashAll()
        Me.Refresh()
    End Sub

    Private Sub PicModel_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PicModel.Paint
        If Not SettingPannel Is Nothing Then
            If ListBoxContour.SelectedIndex >= 0 Then
                If cmbContourFillMode.SelectedIndex = 0 Then '实体填充
                    Dim mySolidBrush As New SolidBrush(SettingPannel.Contours.ArrayContour(ListBoxContour.SelectedIndex).ContourFill.ContourForeColor)
                    e.Graphics.FillRectangle(mySolidBrush, 0, 0, PicModel.Width, PicModel.Height)
                Else
                    Dim myhatchstyle As HatchStyle
                    myhatchstyle = cmbBrushStyle.SelectedIndex '画刷的样式
                    Dim myBrush As New HatchBrush(myhatchstyle, SettingPannel.Contours.ArrayContour(ListBoxContour.SelectedIndex).ContourFill.ContourForeColor, SettingPannel.Contours.ArrayContour(ListBoxContour.SelectedIndex).ContourFill.ContourBackColor)
                    e.Graphics.FillRectangle(myBrush, 0, 0, PicModel.Width, PicModel.Height)
                End If
            End If
        End If
    End Sub

    Private Sub cmdBackColor_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdBackColor.Click
        Dim colorDlg As New ColorDialog
        If Not SettingPannel Is Nothing Then
            colorDlg.Color = SettingPannel.Contours.ArrayContour(ListBoxContour.SelectedIndex).ContourFill.ContourBackColor
            If colorDlg.ShowDialog() = Windows.Forms.DialogResult.OK Then '如果用户点击确定，则将画笔给当前画笔
                Dim i As Double
                For i = 0 To ListBoxContour.SelectedItems.Count - 1
                    SettingPannel.Contours.ArrayContour(ListBoxContour.SelectedIndices(i)).ContourFill.ContourBackColor = colorDlg.Color
                Next
                Me.ReflashAll()
                Me.Refresh()
            End If
        End If
    End Sub

    Private Sub cmdBackColor_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles cmdBackColor.Paint

        If Not SettingPannel Is Nothing Then
            If ListBoxContour.SelectedIndex >= 0 Then
                Dim rect As New Rectangle(5, 5, 30, cmdBackColor.Height - 10)
                Dim LineBrush As New SolidBrush(SettingPannel.Contours.ArrayContour(ListBoxContour.SelectedIndex).ContourFill.ContourBackColor)
                e.Graphics.FillRectangle(LineBrush, rect)
                e.Graphics.DrawRectangle(Pens.Black, rect)
            End If
        End If
    End Sub

    Private Sub cmdForeColor_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdForeColor.Click
        Dim colorDlg As New ColorDialog
        If Not SettingPannel Is Nothing Then
            colorDlg.Color = SettingPannel.Contours.ArrayContour(ListBoxContour.SelectedIndex).ContourFill.ContourForeColor
            If colorDlg.ShowDialog() = Windows.Forms.DialogResult.OK Then '如果用户点击确定，则将画笔给当前画笔
                Dim i As Double
                For i = 0 To ListBoxContour.SelectedItems.Count - 1
                    SettingPannel.Contours.ArrayContour(ListBoxContour.SelectedIndices(i)).ContourFill.ContourForeColor = colorDlg.Color
                Next
                Me.ReflashAll()
                Me.Refresh()
            End If
        End If
    End Sub

    Private Sub cmdForeColor_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles cmdForeColor.Paint
        If ListBoxContour.SelectedIndex >= 0 Then
            If Not SettingPannel Is Nothing Then
                Dim rect As New Rectangle(5, 5, 30, cmdBackColor.Height - 10)
                Dim LineBrush As New SolidBrush(SettingPannel.Contours.ArrayContour(ListBoxContour.SelectedIndex).ContourFill.ContourForeColor)
                e.Graphics.FillRectangle(LineBrush, rect)
                e.Graphics.DrawRectangle(Pens.Black, rect)
            End If
        End If
    End Sub


    '------------------------------------------------------------------------------------


    Private Sub cmbContourFillMode_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbContourFillMode.SelectedIndexChanged
        If cmbContourFillMode.SelectedIndex = 0 Then
            cmbBrushStyle.Enabled = False
            cmdBackColor.Enabled = False
            BackTransparent.Enabled = False

        Else
            cmbBrushStyle.Enabled = True
            cmdBackColor.Enabled = True
            BackTransparent.Enabled = True

        End If
        If Not SettingPannel Is Nothing Then
            '根据当前选中的边轴确定是否绘该座标线
            Dim i As Double
            For i = 0 To ListBoxContour.SelectedItems.Count - 1
                SettingPannel.Contours.ArrayContour(ListBoxContour.SelectedIndices(i)).ContourFill.BrushStyle = cmbContourFillMode.SelectedIndex '画刷样式
            Next
        End If
        Me.Refresh()
        Me.ReflashAll()
    End Sub

    Private Sub chkContourFillVisible_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkContourFillVisible.CheckedChanged
        If Not SettingPannel Is Nothing Then
            '根据当前选中的边轴确定是否绘该座标线
            Dim i As Double
            For i = 0 To ListBoxContour.SelectedItems.Count - 1
                SettingPannel.Contours.ArrayContour(ListBoxContour.SelectedIndices(i)).ContourFill.ContourFillVisible = chkContourFillVisible.Checked
            Next
        End If
        Me.ReflashAll()
    End Sub

    Private Sub ForeTransparent_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ForeTransparent.ValueChanged
        If Not SettingPannel Is Nothing Then
            '根据当前选中的边轴确定是否绘该座标线
            Dim i As Double
            For i = 0 To ListBoxContour.SelectedItems.Count - 1
                SettingPannel.Contours.ArrayContour(ListBoxContour.SelectedIndices(i)).ContourFill.ForeTransparent = ForeTransparent.Value
            Next
        End If
        Me.ReflashAll()
    End Sub

    Private Sub BackTransparent_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BackTransparent.ValueChanged
        If Not SettingPannel Is Nothing Then
            '根据当前选中的边轴确定是否绘该座标线
            Dim i As Double
            For i = 0 To ListBoxContour.SelectedItems.Count - 1
                SettingPannel.Contours.ArrayContour(ListBoxContour.SelectedIndices(i)).ContourFill.BackTransparent = BackTransparent.Value
            Next
        End If
        Me.ReflashAll()
    End Sub

    
    '标志下拉框画笔样式
    Public Sub DrawSymbolItemBrushStyle(ByVal e As System.Windows.Forms.DrawItemEventArgs) '绘制填充样式
        Dim mySymbolShape As New SymbolShape
        Dim rect As New Rectangle(3, e.Bounds.Y + 3, e.Bounds.Height - 6, e.Bounds.Height - 6)
        e.Graphics.FillRectangle(Brushes.RoyalBlue, e.Bounds)
        mySymbolShape.SymbolShapeStyle = e.Index
        mySymbolShape.DrawSymbolShape(e.Graphics, rect)
        e.Graphics.DrawString(arrSymbolShapeName(e.Index), e.Font, Brushes.White, 3 + 3 + e.Bounds.Height - 6, e.Bounds.Y + 3)
        'is the mouse hovering over a combobox item??			
        If (e.State = DrawItemState.None) Then
            'this code keeps the last item drawn from having a Bisque background. 
            e.Graphics.FillRectangle(Brushes.White, e.Bounds)
            mySymbolShape.SymbolShapeStyle = e.Index
            mySymbolShape.DrawSymbolShape(e.Graphics, rect)
            e.Graphics.DrawString(arrSymbolShapeName(e.Index), e.Font, Brushes.Black, 3 + 3 + e.Bounds.Height - 6, e.Bounds.Y + 3)
        End If
    End Sub

    Private Sub cmdContourLableColor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdContourLableColor.Click
        If Not SettingPannel Is Nothing Then
            SettingPannel.Contours.ArrayContour(ListBoxContour.SelectedIndex).ContourLine.LabelColor = cmdContourLableColor.GradColor
            Me.ReflashAll()
            Me.Refresh()
        End If
    End Sub

    ''' <summary>
    ''' 这一函数用来打开线型对话框，并返回相应的线形
    ''' </summary>
    ''' <param name="mypen"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function OpenAndGetLine(ByVal mypen As PenProperty) As PenProperty
        Dim frmLineStyle As New LineStyleEditor
        '分别赋给属性值，进行值传递，并调整宽度比例
        frmLineStyle.penCurLineStyle.DashStyle = mypen.DashStyle
        frmLineStyle.penCurLineStyle.Width = mypen.WidthReal
        frmLineStyle.penCurLineStyle.Color = Color.FromArgb(mypen.color)
        If frmLineStyle.ShowDialog() = Windows.Forms.DialogResult.OK Then '如果用户点击确定，则将线形编程器的画笔给当前画笔
            mypen.DashStyle = frmLineStyle.penCurLineStyle.DashStyle
            mypen.WidthReal = frmLineStyle.penCurLineStyle.Width
            mypen.color = frmLineStyle.penCurLineStyle.Color.ToArgb
        End If
        Return mypen
    End Function

   
    Private Sub cmdOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOK.Click
        Me.ReflashAll()
        Me.DialogResult = Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub
    Private Sub chkSmooth_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkSmooth.CheckedChanged
        Dim i As Integer = 0
        If Not SettingPannel Is Nothing Then
            If chkSmooth.Checked = True Then
                SettingPannel.Symbols.PolluteSymbol.Symbol.SmoothingMode = True
                SettingPannel.Symbols.PolluteSymbol.Symbol.SymbolText.SmoothingMode = True
                SettingPannel.Symbols.CareSymbols.Symbol.SmoothingMode = True
                SettingPannel.Symbols.CareSymbols.Symbol.SymbolText.SmoothingMode = True
                For i = 0 To SettingPannel.Contours.ArrayContour.Length - 1
                    SettingPannel.Contours.ArrayContour(i).ContourLine.SmoothingMode = True
                Next
                SettingPannel.Legend.SmoothingMode = True
            Else
                SettingPannel.Symbols.PolluteSymbol.Symbol.SmoothingMode = False
                SettingPannel.Symbols.PolluteSymbol.Symbol.SymbolText.SmoothingMode = False
                SettingPannel.Symbols.CareSymbols.Symbol.SmoothingMode = False
                SettingPannel.Symbols.CareSymbols.Symbol.SymbolText.SmoothingMode = False
                For i = 0 To SettingPannel.Contours.ArrayContour.Length - 1
                    SettingPannel.Contours.ArrayContour(i).ContourLine.SmoothingMode = False
                Next
                SettingPannel.Legend.SmoothingMode = False
            End If
            Me.ReflashAll()
        End If
    End Sub

    Private Sub picBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub cmdSetContours_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSetContours.Click
        'Dim newdlgInitialContour As New dlgInitialContour
        'Dim i As Integer
        'newdlgInitialContour.DataGridContour.RowCount = ActivePaintForm.ContourPaintSetting.ContourValue.Length + 1
        'For i = 0 To ActivePaintForm.ContourPaintSetting.ContourValue.Length - 1
        '    newdlgInitialContour.DataGridContour.Item(0, i).Value = ActivePaintForm.ContourPaintSetting.ContourNames(i)
        '    newdlgInitialContour.DataGridContour.Item(1, i).Value = ActivePaintForm.ContourPaintSetting.ContourValue(i)
        'Next
        'If newdlgInitialContour.ShowDialog() = Windows.Forms.DialogResult.OK Then
        '    ReDim ActivePaintForm.ContourPaintSetting.ContourNames(newdlgInitialContour.DataGridContour.RowCount - 2)
        '    ReDim ActivePaintForm.ContourPaintSetting.ContourValue(newdlgInitialContour.DataGridContour.RowCount - 2)
        '    For i = 0 To ActivePaintForm.ContourPaintSetting.ContourValue.Length - 1
        '        ActivePaintForm.ContourPaintSetting.ContourNames(i) = newdlgInitialContour.DataGridContour.Item(0, i).Value
        '        ActivePaintForm.ContourPaintSetting.ContourValue(i) = newdlgInitialContour.DataGridContour.Item(1, i).Value
        '    Next
        '    ListBoxContour.Items.Clear()
        '    For i = 0 To ActivePaintForm.ContourPaintSetting.ContourValue.Length - 1
        '        ListBoxContour.Items.Add(CSng(ActivePaintForm.ContourPaintSetting.ContourValue(i))) '加入等值线值
        '    Next
        '    ActivePaintForm.ContourPaintSetting.ResetCountData()
        '    SettingPannel.Contours.ReCalContour = True '重新计算等值线及区域
        'End If
        'Me.ReflashAll()

        Dim newdlgInitialContour As New dlgAermodGradient
        '设置最小值和最大值及间距
        newdlgInitialContour.txtGradMix.Value = ActivePaintForm.ContourPaintSetting.ContourPannel.Contours.ContourValueSetting.ContourMin
        newdlgInitialContour.txtGradMax.Value = ActivePaintForm.ContourPaintSetting.ContourPannel.Contours.ContourValueSetting.ContourMax
        newdlgInitialContour.txtDistanse.Value = ActivePaintForm.ContourPaintSetting.ContourPannel.Contours.ContourValueSetting.ContourIntel
        '设置等值线数组
        newdlgInitialContour.A = ActivePaintForm.ContourPaintSetting.ContourPannel.Contours.ContourValueSetting.ContourValue
        '设置选中的类型
        If ActivePaintForm.ContourPaintSetting.ContourPannel.Contours.ContourValueSetting.ContourValueType = 0 Then
            newdlgInitialContour.RadioButtonGrade.Checked = True
            newdlgInitialContour.RadioButtonCustom.Checked = False
        Else
            newdlgInitialContour.RadioButtonGrade.Checked = False
            newdlgInitialContour.RadioButtonCustom.Checked = True
        End If

        If newdlgInitialContour.ShowDialog() = Windows.Forms.DialogResult.OK Then
            ActivePaintForm.ContourPaintSetting.ContourPannel.Contours.ContourValueSetting.ContourValue = newdlgInitialContour.A
            '清空列表，并加入
            ListBoxContour.Items.Clear()
            If newdlgInitialContour.RadioButtonGrade.Checked = True Then
                '设置等值线值的类型
                ActivePaintForm.ContourPaintSetting.ContourPannel.Contours.ContourValueSetting.ContourValueType = 0
                '设置等值线
                ActivePaintForm.ContourPaintSetting.ContourPannel.Contours.ContourValueSetting.SetContourValue(newdlgInitialContour.txtGradMix.Value, newdlgInitialContour.txtGradMax.Value, newdlgInitialContour.txtDistanse.Value)
                For i As Integer = 0 To ActivePaintForm.ContourPaintSetting.ContourPannel.Contours.ContourValueSetting.ContourValue.Length - 1
                    ListBoxContour.Items.Add(CSng(ActivePaintForm.ContourPaintSetting.ContourPannel.Contours.ContourValueSetting.ContourValue(i))) '加入等值线值
                Next
                '重新设置等值线数据
                ActivePaintForm.ContourPaintSetting.ContourPannel.Contours.ResetContourData(ActivePaintForm.ContourPaintSetting.ContourPannel.Contours.ContourValueSetting.ContourValue)
                '重新计算等值线及区域 Else
            Else
                '设置等值线值的类型
                ActivePaintForm.ContourPaintSetting.ContourPannel.Contours.ContourValueSetting.ContourValueType = 1
                ReDim ActivePaintForm.ContourPaintSetting.ContourPannel.Contours.ContourValueSetting.ContourNames(newdlgInitialContour.A.Length - 1)
                For i As Integer = 0 To newdlgInitialContour.A.Length - 1
                    ActivePaintForm.ContourPaintSetting.ContourPannel.Contours.ContourValueSetting.ContourNames(i) = newdlgInitialContour.A(i)
                    ActivePaintForm.ContourPaintSetting.ContourPannel.Contours.ContourValueSetting.ContourValue(i) = newdlgInitialContour.A(i)
                    ListBoxContour.Items.Add(CSng(ActivePaintForm.ContourPaintSetting.ContourPannel.Contours.ContourValueSetting.ContourValue(i))) '加入等值线值
                Next
                '重新设置等值线数据
                ActivePaintForm.ContourPaintSetting.ContourPannel.Contours.ResetContourData(ActivePaintForm.ContourPaintSetting.ContourPannel.Contours.ContourValueSetting.ContourValue)
                '重新计算等值线及区域 Else
            End If
            If ListBoxContour.Items.Count > 0 Then
                ListBoxContour.SelectedIndex = 0
            End If
        End If
        Me.ReflashAll()
    End Sub

    

    Private Sub txtNumber_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtNumber.TextChanged
        If Not SettingPannel Is Nothing Then
            Dim i As Double
            For i = 0 To ListBoxContour.Items.Count - 1
                SettingPannel.Contours.ArrayContour(i).ContourLine.Number = txtNumber.Value
            Next
        End If
        Me.ReflashAll()
    End Sub

    Private Sub txtPels_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtPels.Validating
        publicVar.PannelSetting.gWidthPels = Me.txtPels.Value
    End Sub

    Private Sub chkSlip_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkSlip.CheckedChanged
        Me.SettingPannel.Contours.Slip = Me.chkSlip.Checked
        Me.SettingPannel.Contours.ReSetContoursSlip()
        Me.Refresh()
    End Sub
End Class